package cn.lixu._01sync;

import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

import java.nio.charset.StandardCharsets;

/**
 * @author LiXu
 * @date 2022/08/17 0017 23:34:14
 */
public class Producter_1 {
    public static void main(String[] args) throws Exception {
        //1.创建对象，获取生产者对象
        DefaultMQProducer producer = new DefaultMQProducer("producter_hello_world");
        //2.设置连接地址值
        producer.setNamesrvAddr("localhost:9876");
        //3.启动
        producer.start();
        //4.创建消息对象并进行设置
        Message message = new Message("hello_world", "hello", "我爱中国，我爱四川，我爱成都".getBytes(StandardCharsets.UTF_8));
        SendResult send = producer.send(message);
        System.out.println(send);
        //5.关闭连接
        producer.shutdown();


    }
}
